<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>1.11. Catching Gdata Exceptions</title>
<link rel="stylesheet" href="dbstyle.css" type="text/css">
<meta name="generator" content="DocBook XSL Stylesheets V1.72.0">
<link rel="start" href="index.html" title="Programmer's Reference Guide">
<link rel="up" href="zend.gdata.html" title="Chapter 1. Zend_Gdata">
<link rel="prev" href="zend.gdata.youtube.html" title="1.10. Using the YouTube Data API">
<link rel="next" href="migration.html" title="Appendix A. ">
<link rel="chapter" href="zend.gdata.html" title="Chapter 1. Zend_Gdata">
<link rel="appendix" href="migration.html" title="Appendix A. ">
<link rel="appendix" href="performance.html" title="Appendix B. ">
<link rel="index" href="the.index.html" title="Index">
</head>
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
<div class="navheader"><table width="100%" summary="Navigation header">
<tr><th colspan="3" align="center">1.11. Catching Gdata Exceptions</th></tr>
<tr>
<td width="20%" align="left">
<a accesskey="p" href="zend.gdata.youtube.html">Prev</a> </td>
<th width="60%" align="center">Chapter 1. Zend_Gdata</th>
<td width="20%" align="right"> <a accesskey="n" href="migration.html">Next</a>
</td>
</tr>
</table></div>
<div class="sect1" lang="en">
<div class="titlepage"><div><div><h2 class="title" style="clear: both">
<a name="zend.gdata.exception"></a>1.11. Catching Gdata Exceptions</h2></div></div></div>
<p>
        The <code class="classname">Zend_Gdata_App_Exception</code> class is a base class
        for exceptions thrown by <code class="classname">Zend_Gdata</code>. You can catch any exception
        thrown by <code class="classname">Zend_Gdata</code> by catching <code class="classname">Zend_Gdata_App_Exception</code>.
    </p>
<pre class="programlisting">
try {
    $client =
        Zend_Gdata_ClientLogin::getHttpClient($username, $password);
} catch(Zend_Gdata_App_Exception $ex) {
    // Report the exception to the user
    die($ex-&gt;getMessage());
}
</pre>
<p>
        The following exception subclasses are used by <code class="classname">Zend_Gdata</code>:

        </p>
<div class="itemizedlist"><ul type="disc">
<li><p>
                    <code class="classname">Zend_Gdata_App_AuthException</code>
                    indicates that the user's account credentials were not valid.
                </p></li>
<li><p>
                    <code class="classname">Zend_Gdata_App_BadMethodCallException</code>
                    indicates that a method was called for a service
                    that does not support the method. For example,
                    the CodeSearch service does not support <code class="methodname">post()</code>.
                </p></li>
<li><p>
                    <code class="classname">Zend_Gdata_App_HttpException</code>
                    indicates that an <acronym class="acronym">HTTP</acronym> request was not successful.
                    Provides the ability to get the full <code class="classname">Zend_Http_Response</code>
                    object to determine the exact cause of the failure in
                    cases where <span><strong class="command">$e-&gt;getMessage()</strong></span> does not provide
                    enough details.
                </p></li>
<li><p>
                    <code class="classname">Zend_Gdata_App_InvalidArgumentException</code>
                    is thrown when the application provides a value that
                    is not valid in a given context. For example,
                    specifying a Calendar visibility value of "banana",
                    or fetching a Blogger feed without specifying
                    any blog name.
                </p></li>
<li><p>
                  <code class="classname">Zend_Gdata_App_CaptchaRequiredException</code>
                  is thrown when a ClientLogin attempt receives a
                  <span class="trademark">CAPTCHA</span>™ challenge from the
                  authentication service. This exception contains a token
                  ID and a <acronym class="acronym">URL</acronym> to a <span class="trademark">CAPTCHA</span>™
                  challenge image. The image is a visual puzzle that
                  should be displayed to the user. After
                  collecting the user's response to the challenge
                  image, the response can be included with the next
                  ClientLogin attempt.The user can alternatively be
                  directed to this website:
                  <a href="https://www.google.com/accounts/DisplayUnlockCaptcha" target="_top">https://www.google.com/accounts/DisplayUnlockCaptcha</a>
                  Further information can be found in the
                  <a href="zend.gdata.clientlogin.html" title="1.3. Authenticating with ClientLogin">ClientLogin documentation</a>.
                </p></li>
</ul></div>
<p>
    </p>
<p>
        You can use these exception subclasses to handle specific exceptions
        differently. See the <acronym class="acronym">API</acronym> documentation for information on which
        exception subclasses are thrown by which methods in <code class="classname">Zend_Gdata</code>.
    </p>
<pre class="programlisting">
try {
    $client = Zend_Gdata_ClientLogin::getHttpClient($username,
                                                    $password,
                                                    $service);
} catch(Zend_Gdata_App_AuthException $authEx) {
    // The user's credentials were incorrect.
    // It would be appropriate to give the user a second try.
    ...
} catch(Zend_Gdata_App_HttpException $httpEx) {
    // Google Data servers cannot be contacted.
    die($httpEx-&gt;getMessage);}
</pre>
</div>
<div class="navfooter"><table width="100%" summary="Navigation footer">
<tr>
<td width="40%" align="left">
<a accesskey="p" href="zend.gdata.youtube.html">Prev</a> </td>
<td width="20%" align="center"><a accesskey="u" href="zend.gdata.html">Up</a></td>
<td width="40%" align="right"> <a accesskey="n" href="migration.html">Next</a>
</td>
</tr>
<tr>
<td width="40%" align="left" valign="top">1.10. Using the YouTube Data API </td>
<td width="20%" align="center"><a accesskey="h" href="index.html">Home</a></td>
<td width="40%" align="right" valign="top"> Appendix A. </td>
</tr>
</table></div>
<div class="revinfo"></div>
</body>
</html>
